#!/usr/bin/env python
# child python script

### Imports ###
import os		# provide output to command prompt
import sys		# flush command prompt output
import argparse

# Check if SDK_SETUP_ENV is set or not for checking whether environment is set or not.
# Exit walkthrough if SDK_SETUP_ENV is not set.
if not os.getenv('SDK_SETUP_ENV'):
		sys.exit("\nSDK Environment not set up -> please run setup_sdk_env script from SDK's root directory.")

hexagon_sdk_root = os.getenv('HEXAGON_SDK_ROOT')
script_dir = hexagon_sdk_root + '/utils/scripts/'
example_path=os.curdir

sys.path.append(script_dir)
import common_walkthrough as CW

pid = os.getpid()	# return the current process ID
received = False	# initialize signal received to false

example_name = "tracker_kcf"
unsupported_target_info = ["qcs403","qcs405","agatti","strait","monaco","divar"]

def add_args_to_parser(parser):
	pass

def main():

    # Adding example arguments to common walkthrough parser
    add_args_to_parser(CW.parser)

    # Making object of class device
    device = CW.device()
    if device.name in unsupported_target_info:
        print("ERROR: Device {} is not supported".format(device.name))
        sys.exit()

    # building for HLOS
    hlos_dir = device.build_hlos(example_path)
    # building for dsp
    dsp_dir = device.build_hexagon(example_path)
    # Signing the device
    device.sign()
    options = CW.get_options()
    example_exe = '{}/{}/ship/{}'.format(example_path,hlos_dir,example_name)
    libasyncdspq = '{}/{}/libtracker_kcf.so'.format(example_path,hlos_dir)
    libexample_skel = '{}/{}/ship/lib{}_skel.so'.format(example_path,dsp_dir,example_name)

    executables = [example_exe]
    hlos_libs = [libasyncdspq]
    dsp_libs = [libexample_skel]

    device.copy_binaries_to_target(executables,hlos_libs,dsp_libs)

    args = '-d {} -U {}'.format(options.domain,options.unsigned)
    args_list = list()
    args_list.append(args)

    # Run Example on device
    print("--- Run tracker_kcf on domain {}".format(options.domain))
    device.run(example_name,args_list)


if __name__ == '__main__':
    main()
    sys.stdout.flush()
